<#include '/pages/taglib/core.ftl'>
<#include '/pages/taglib/common.ftl'>

<#macro importsetting name='' targetModelProperties=[] excelColumnVar='excelColumns' style='' clazz=''>
	<#local shortName = tag.getShortName(name)>
	<#assign pElement = ps.checkAddElement(shortName, name, 'importsetting', {'targetModelProperties':targetModelProperties})>
	<#local modelService = fn.service('model')>
	
<#local cid = tag.getCid(name, 'importsetting')>
<div fullName='${name}' class="jimportsetting stdEle ${clazz}" <#if style!=''> style="${style}"</#if> uiType='export'>
	<table class="tablelist columnMapping">
		<thead>
			<tr>
				<th><div class="th" style="text-align:right;width:240px;padding-right:5px"><@i18n name='系统字段'/></div></th>
				<th><div class="th"><@i18n name='映射'/></div></th>
				<th><div class="th"><@i18n name='导入字段(鼠标移动调整)'/></div></th>
				<th><div class="th"><@i18n name='废弃字段(鼠标移动至导入字段)'/></div></th>
			</tr>
		</thead>
		<tbody>
		<tr>
			<td style="vertical-align: top;">
				<ul class="columnsource">
				<#list targetModelProperties as name>
					<#if name!=''>
						<li><span>${modelService.getModelFieldI18n(null,name)}(${name})</span></li>
					<#else>
						<li><span> </span></li>
					</#if>
				</#list>
				</ul>
			</td>
			<td>
				&lt;==&gt;
			</td>
			<td style="vertical-align: top;">
				<ul id="targetColumn1_${cid}" class="sortable hover">
				<#local excelSourceColumns=fn.val(action, excelColumnVar)![]>
				<#list excelSourceColumns as columnName>
					<li>
						<span>${columnName}</span>
						<#if name == ''>
							<input type="hidden" name="model.mappingColumns" value="-1" origValue="-1">
						<#else>
							<input type="hidden" name="model.mappingColumns" value="${columnName_index}" origValue="${columnName_index}">
						</#if>
						<div class="tinyClose" onclick="removeSortableItem(this)"></div>
					</li>
				</#list>
				</ul>
			</td>
			<td style="vertical-align: top;">
				<ul id="targetColumn3_${cid}" class="sortable hover">
					<li id="emptyElement_${cid}" class="cloneColumn emptyColumn"><span><@i18n name="空例 (不导入)"/></span><input type="hidden" name="model.mappingColumns" value="-1" origValue="-1"></li>
				</ul>
			</td>
		</tr>
	</table>
	
	<script>
	if (typeof($)=='undefined') {
		$ = parent.$;
		getCss = parent.getCss;
	}
	<#local cssPath = tag.getCssPath(ps, '', '/static/espirit/styles/espirit/common/generic.analyseImportFileColumns.css')>
	getCss('${cssPath}');
	when('$.fn.sortable', function() {
		if (typeof(moveSortableItem)=='undefined') {
			moveSortableItem = parent.moveSortableItem;
		}
		var minHeight = $('#targetColumn1_${cid}').height();
		$('#targetColumn1_${cid}').css('min-height', minHeight + 'px');
		$("#targetColumn1_${cid}")
			.sortable({placeholder: "sortableHighlight",connectWith: ".sortable"})
			.droppable({
				activeClass: "ui-state-default",
				hoverClass: "ui-state-hover",
				drop: moveSortableItem
			});
		$("#targetColumn1_${cid}").disableSelection();
		$("#emptyElement_${cid}" ).draggable({helper: "clone", appendTo: "#targetColumn1_${cid}"});
	});
	</script>
</div>
</#macro>

<#assign tmp = ps.safeContext().addCssCategory('common')>